﻿using System;
using System.Collections;
using System.Collections.Generic;
using JetBrains.Annotations;
using UBlockly.Compotent;
using UnityEngine;
using UBlockly.Scriptable;
using UBlockly.Util;

namespace UBlockly.Graphic
{
    internal sealed class BlockResource
    {
        private BlockGraphicAsset graphicAsset;
        private BlockSoundAsset soundAsset;
        public BlockResource()
        {
            
        }

        public void SetGraphicAsset(BlockGraphicAsset asset)
        {
            graphicAsset = asset;
        }
        public void SetSoundAsset(BlockSoundAsset asset)
        {
            soundAsset = asset;
        }

        public Font GetFont()
        {
            return graphicAsset.GetFont();
        }

        public Color GetColor(string key)
        {
            var color = graphicAsset.GetColor(key);
            if (color != null)
                return color.Value;
            throw new SystemException($"GetColor {key} error");
        }

        public Sprite GetSprite(string key)
        {
            var sprite = graphicAsset.GetSprite(key);
            return sprite?? throw new SystemException($"GetSprite {key} error");
        }

        public float GetSize(string key)
        {
            return graphicAsset.GetSize(key);
        }

        public IParamGetterCompotent InstanceParamGetter(string key)
        {
            var go = graphicAsset.GetParamGetter(key);
            if (go != null)
                return GameObject.Instantiate(go.gameObject).GetComponent<IParamGetterCompotent>();
            throw new SystemException($"InstanceParamGetter {key} error");
        }

        public IParamSetterPanel GetParamSetterPanel(string key)
        {
            var go = graphicAsset.GetParamSetterPanel(key);
            if (go != null)
                return go;
            return null;
        }

        public AudioClip GetClip(string key)
        {
            return soundAsset?.GetClip(key);
        }
    }

}
